package com.zyc.controller;

import com.zyc.commonUtils.R;
import com.zyc.service.VodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author zyc
 * @create 2022-02-22-22:26
 */
@Api("阿里云视频点播微服务")
@CrossOrigin //跨域
@RestController
@RequestMapping("eduvod/file")
public class VodController {

    @Autowired
    private VodService vodService;

    @ApiOperation("上传视频")
    @PostMapping("upload")
    public R uploadVideo(
            @ApiParam(name = "file", value = "文件", required = true)
            @RequestParam("file") MultipartFile file) throws Exception {

        String videoId = vodService.uploadVideo(file);
        return R.ok().message("视频上传成功").data("videoId", videoId);
    }

    @ApiOperation("根据id删除视频")
    @DeleteMapping("delete/{id}")
    public R deleteVideo(@ApiParam(name = "id", value = "视频id", required = true) @PathVariable String id) {
        System.out.println(id);
        vodService.deleteVideoById(id);
        return R.ok();
    }


}
